﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using VO;

namespace DAL
{
    public class SACH_DAO : ketnoi
    {
        public bool SACH_Insert(SACH_VO data)
        {
            try
            {
                using (SqlCommand dbCmd = new SqlCommand("Sach_Insert", GetConnection()))
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.Parameters.Add(new SqlParameter("@MaS", data.MaS));
                    dbCmd.Parameters.Add(new SqlParameter("@TenS", data.TenS));
                    dbCmd.Parameters.Add(new SqlParameter("@Gia", data.Gia));
                    dbCmd.Parameters.Add(new SqlParameter("@NXB", data.NXB));
                    dbCmd.Parameters.Add(new SqlParameter("@NamXB", data.NamXB));
                    dbCmd.Parameters.Add(new SqlParameter("@SL", data.SL));
                    dbCmd.Parameters.Add(new SqlParameter("@SlMuon", data.SlMuon));                    
                    dbCmd.ExecuteNonQuery();
                }
            }
            catch
            {

            }

            return true;
        }
        //HIEN THI
        public bool SACH_SELECT(SACH_VO data)
        {
            using (SqlCommand dbCmd = new SqlCommand("Sach_SelectAll", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@MaS", data.MaS));
                dbCmd.Parameters.Add(new SqlParameter("@TenS", data.TenS));
                dbCmd.Parameters.Add(new SqlParameter("@Gia", data.Gia));
                dbCmd.Parameters.Add(new SqlParameter("@NXB", data.NXB));
                dbCmd.Parameters.Add(new SqlParameter("@NamXB", data.NamXB));
                dbCmd.Parameters.Add(new SqlParameter("@SL", data.SL));
                dbCmd.Parameters.Add(new SqlParameter("@SlMuon", data.SlMuon));     
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
        //EDIT
        public bool SACH_UPDATE(SACH_VO data)
        {
            using (SqlCommand dbCmd = new SqlCommand("Sach_Update", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@MaS", data.MaS));
                dbCmd.Parameters.Add(new SqlParameter("@TenS", data.TenS));
                dbCmd.Parameters.Add(new SqlParameter("@Gia", data.Gia));
                dbCmd.Parameters.Add(new SqlParameter("@NXB", data.NXB));
                dbCmd.Parameters.Add(new SqlParameter("@NamXB", data.NamXB));
                dbCmd.Parameters.Add(new SqlParameter("@SL", data.SL));
                dbCmd.Parameters.Add(new SqlParameter("@SlMuon", data.SlMuon)); 
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
        //Hien thi
       
        //XOA
        public bool SACH_DELETE(string MaS)
        {
            try
            {

                using (SqlCommand dbCmd = new SqlCommand("Sach_Delete", GetConnection()))
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.Parameters.Add(new SqlParameter("@MaS", MaS));
                    dbCmd.ExecuteNonQuery();
                }
            }
            catch
            {

            }
            return true;
        }
    }
}
